package main

import (
	"context"
	"flag"
	"fmt"

	v1 "gitee.com/youkelike/ziam/zapi/apiserver/v1"
	metav1 "gitee.com/youkelike/ziam/zapi/meta/v1"
	"gitee.com/youkelike/ziam/zsdk2/gosdk"
	"gitee.com/youkelike/ziam/zsdk2/rest"
	"gitee.com/youkelike/zlog"
)

func main() {
	apiserverconfig := flag.String("config", `D:\goproject\ziam\config\zsdk2-apiserver.yaml`, "absolute path to the config file")
	flag.Parse()
	zlog.Infow("===", zlog.String("apiserverconfig", *apiserverconfig))

	config, err := rest.ConfigFromFile(*apiserverconfig)
	if err != nil {
		panic(err.Error())
	}
	// zlog.Infow("===", zlog.Any("config", *config))

	client, err := gosdk.NewForConfig(config)
	if err != nil {
		panic(err.Error())
	}

	fmt.Println("Authorize request...")

	s := &v1.Secret{}
	s.ObjectMeta.Name = "mary"
	ret, err := client.Ziam().APIV1().Secrets().Create(context.Background(), s, metav1.CreateOptions{})
	if err != nil {
		panic(err.Error())
	}

	zlog.Infow("===", zlog.Any("ret", ret))
}
